package com.hh.BacktrackQuestions;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;

/**
 * @Author hanghao
 * @Date 2023/7/7 13:40
 * @Version 1.0
 */

public class No77 {
    List<List<Integer>> res = new ArrayList<List<Integer>>();
    LinkedList<Integer> path = new LinkedList<Integer>();
    public List<List<Integer>> combine(int n, int k) {

        backTracking(n,k,1);
        return res;
    }

    private void backTracking(int n, int k, int startIndex) {
        if(path.size() == k) {
            res.add(new ArrayList(path));
            return;
        }
        for (int i = startIndex; i <= n - (k - path.size()) + 1; i++) {
            path.add(i);
            backTracking(n,k,i + 1);
            path.removeLast();
        }
    }
}
